/****************************************************
 * 创建人:   robin
 * 创建时间: 2023/9/1.001 10:57
 * 项目名称: cpy
 * 文件名称: PsdpFeignHystrix.java
 * 文件描述: 
 *
 * All rights Reserved, Designed By 德品软件
 * @Copyright:2023-2023
 *
 ********************************************************/
package com.dp.feign;

import com.dp.feign.vo.request.AddTradRecord4ReqVO;
import com.dp.feign.vo.request.EditDtuInfoReqVO;
import com.dp.feign.vo.request.EditOilTankReqVO;
import com.dp.feign.vo.request.LoginReqVO;
import com.dp.feign.vo.response.GetDtuInfoByNameRspVO;
import com.dp.feign.vo.response.LoginRspVO;
import com.dp.feign.vo.response.PsdpResponseData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

/**
 * 包名称：com.dp.feign
 * 类名称：PsdpFeignHystrix
 * 类描述：
 * 创建人： robin
 * 创建时间：2023/9/1.001 10:57
 */
@Slf4j
public class PsdpFeignHystrix implements FallbackFactory<PsdpFeign> {
    
    @Override
    public PsdpFeign create(Throwable cause) {
        return new PsdpFeign(){
            @Override
            public PsdpResponseData<LoginRspVO> login(LoginReqVO loginReqVO) {
                return handHystrix(cause);
            }
    
            @Override
            public PsdpResponseData editOilTank(EditOilTankReqVO editOilTankReqVO, String token) {
                return handHystrix(cause);
            }
    
            @Override
            public PsdpResponseData<GetDtuInfoByNameRspVO> getDtuInfoByName(String name, String token) {
                return handHystrix(cause);
            }
    
            @Override
            public PsdpResponseData editDtuInfo(EditDtuInfoReqVO editDtuInfoReqVO, String token) {
                return handHystrix(cause);
            }
    
            @Override
            public PsdpResponseData addTradRecord(String apiAdd, AddTradRecord4ReqVO addTradRecord4ReqVO, String threadName, Integer port, String token) {
                return handHystrix(cause);
            }
        };
    }
    
    private PsdpResponseData handHystrix(Throwable throwable) {
        log.error("服务不存在或网络断开,错误原因:{}", throwable.getMessage());
        return PsdpResponseData.handleError(false, "服务不存在或网络断开,错误原因:" + throwable.getMessage(), 500, null, 0L);
    }
}
